function vote(aid) {

FB.getLoginStatus(function(stsResp) {
        if(stsResp.authResponse) {
          send_vote(aid);
        } else {
          FB.login(function(loginResp) {
            if(loginResp.authResponse) {
              send_vote(aid);
            } else {
              alert("Please authorize this application to use it!");
            }
          });
        }
      });

}

function send_vote(aid) {
  $.ajax({
    type: 'POST',
    url: globals['base_url'] + 'gallery/vote/' + aid,
    success: function(json) {
      resp = JSON.parse(json);
      if(resp.message == 'success') {
        $('.popup-avatar-votes').html(resp.votes);
        $('.popup-vote-button').hide();
      }
    }
  });
}